import { createStore } from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import Env from '@/env'

import test from './modules/test' // 引入模块
import mpWxPos from './modules/mpWxPos'
import jwt from './modules/jwt'

export default createStore({
	plugins: [
		createPersistedState({
			key: Env.cachePrefix + `-vuex4-`, // 存储键名
			storage: {
				getItem: (key) => uni.getStorageSync(key),
				setItem: (key, value) => uni.setStorageSync(key, value),
				removeItem: (key) => uni.removeStorageSync(key)
			} /*,
			reducer: (state) => {
				// 排除 test1 模块
				const { test1, ...rest } = state
				return rest
			}*/
		})
	],
	modules: {
		test,
		mpWxPos,
		jwt
	}
})
